import requests from '@src/common/request'
import qqMapWX from "@src/common/qqmap/map";
export function getStoreList() {
  return requests.post(
      {
        url: '/mall/anon/store/list',
        data: {
          storeListQuery: {
            latitude: 0,
            longitude: 0,
            name: "xxx"
          }
        }
      }
  )
}

//新增地址
export function addAddress(form) {
  return requests.post({
    url: '/mall/mobile/address/add',
    data: form
  })
}

//获取地址列表
export function getAddressList() {
  return requests.get('/mall/mobile/address/list')
}

//删除地址
export function deleteById(addressId) {
  return requests.delete('/mall/mobile/address/delete?addressId=' + addressId)
}

//更新地址
export function updateAddress(form) {
  return requests.post({
    url: '/mall/mobile/address/update',
    data:form
  })
}

//获取用户手机号
export function getUserPhone(temp) {
  return requests.post({
    url: '/wx/user/base/phone',
    data:temp
  })
}

export function getSuggest(keyword, region) {
  return new Promise((resolve, reject) => {
    //调用关键词提示接口
    qqMapWX.getSuggestion({
      //获取输入框值并设置keyword参数
      keyword: keyword, //用户输入的关键词，可设置固定值,如keyword:'KFC'
      region: region, //设置城市名，限制关键词所示的地域范围，非必填参数
      success: function (res) {//搜索成功后的回调
        console.log(res);
        var sug = [];
        for (var i = 0; i < res.data.length; i++) {
          sug.push({ // 获取返回结果，放到sug数组中
            title: res.data[i].title,
            id: res.data[i].id,
            addr: res.data[i].address,
            city: res.data[i].city,
            district: res.data[i].district,
            latitude: res.data[i].location.lat,
            longitude: res.data[i].location.lng
          });
          resolve(sug)
        }
        // _this.setData({ //设置suggestion属性，将关键词搜索结果以列表形式展示
        //   suggestion: sug
        // });
      },
      fail: function (error) {
        console.error(error);
        reject(error)
      },
      complete: function (res) {
        console.log(res);
      }
    });
  })
}
